Conditions | 1 |
Paths | 1 |
Total Lines | 140 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | module.exports = function(GedcomX){ |
||
2 | |||
3 | var utils = require('../utils'), |
||
4 | AtomCommon = require('./AtomCommon'); |
||
5 | |||
6 | /** |
||
7 | * Information about a category associated with an atom entry or feed. |
||
8 | * |
||
9 | * @see {@link https://github.com/FamilySearch/gedcomx-rs/blob/master/specifications/atom-model-specification.md#atom-json-media-type|GEDCOM X Atom JSON Spec} |
||
10 | * @see {@link https://tools.ietf.org/html/rfc4287#section-4.2.2|RFC 4287} |
||
11 | * |
||
12 | * @class AtomCategory |
||
13 | * @extends AtomCommon |
||
14 | * @param {Object} [json] |
||
15 | */ |
||
16 | var AtomCategory = function(json){ |
||
17 | |||
18 | // Protect against forgetting the new keyword when calling the constructor |
||
19 | if(!(this instanceof AtomCategory)){ |
||
20 | return new AtomCategory(json); |
||
21 | } |
||
22 | |||
23 | // If the given object is already an instance then just return it. DON'T copy it. |
||
24 | if(AtomCategory.isInstance(json)){ |
||
25 | return json; |
||
26 | } |
||
27 | |||
28 | this.init(json); |
||
|
|||
29 | }; |
||
30 | |||
31 | AtomCategory.prototype = Object.create(AtomCommon.prototype); |
||
32 | |||
33 | AtomCategory._gedxClass = AtomCategory.prototype._gedxClass = 'GedcomX.AtomCategory'; |
||
34 | |||
35 | AtomCategory.jsonProps = [ |
||
36 | 'scheme', |
||
37 | 'term', |
||
38 | 'label' |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * Check whether the given object is an instance of this class. |
||
43 | * |
||
44 | * @param {Object} obj |
||
45 | * @returns {Boolean} |
||
46 | */ |
||
47 | AtomCategory.isInstance = function(obj){ |
||
48 | return utils.isInstance(obj, this._gedxClass); |
||
49 | }; |
||
50 | |||
51 | /** |
||
52 | * Initialize from JSON |
||
53 | * |
||
54 | * @param {Object} |
||
55 | * @return {AtomCategory} this |
||
56 | */ |
||
57 | AtomCategory.prototype.init = function(json){ |
||
58 | |||
59 | AtomCommon.prototype.init.call(this, json); |
||
60 | |||
61 | if(json){ |
||
62 | this.setScheme(json.scheme); |
||
63 | this.setTerm(json.term); |
||
64 | this.setLabel(json.label); |
||
65 | } |
||
66 | return this; |
||
67 | }; |
||
68 | |||
69 | /** |
||
70 | * Set the scheme |
||
71 | * |
||
72 | * @param {String} scheme |
||
73 | * @return {AtomCategory} this |
||
74 | */ |
||
75 | AtomCategory.prototype.setScheme = function(scheme){ |
||
76 | this.scheme = scheme; |
||
77 | return this; |
||
78 | }; |
||
79 | |||
80 | /** |
||
81 | * Get the scheme |
||
82 | * |
||
83 | * @return {AtomCategory} this |
||
84 | */ |
||
85 | AtomCategory.prototype.getScheme = function(){ |
||
86 | return this.scheme; |
||
87 | }; |
||
88 | |||
89 | /** |
||
90 | * Set the term |
||
91 | * |
||
92 | * @param {String} term |
||
93 | * @return {AtomCategory} this |
||
94 | */ |
||
95 | AtomCategory.prototype.setTerm = function(term){ |
||
96 | this.term = term; |
||
97 | return this; |
||
98 | }; |
||
99 | |||
100 | /** |
||
101 | * Get the term |
||
102 | * |
||
103 | * @return {AtomCategory} this |
||
104 | */ |
||
105 | AtomCategory.prototype.getTerm = function(){ |
||
106 | return this.term; |
||
107 | }; |
||
108 | |||
109 | /** |
||
110 | * Set the label |
||
111 | * |
||
112 | * @param {String} label |
||
113 | * @return {AtomCategory} this |
||
114 | */ |
||
115 | AtomCategory.prototype.setLabel = function(label){ |
||
116 | this.label = label; |
||
117 | return this; |
||
118 | }; |
||
119 | |||
120 | /** |
||
121 | * Get the label |
||
122 | * |
||
123 | * @return {AtomCategory} this |
||
124 | */ |
||
125 | AtomCategory.prototype.getLabel = function(){ |
||
126 | return this.label; |
||
127 | }; |
||
128 | |||
129 | /** |
||
130 | * Export the object as JSON |
||
131 | * |
||
132 | * @return {Object} JSON object |
||
133 | */ |
||
134 | AtomCategory.prototype.toJSON = function(){ |
||
135 | return this._toJSON(AtomCommon, AtomCategory.jsonProps); |
||
136 | }; |
||
137 | |||
138 | GedcomX.AtomCategory = AtomCategory; |
||
139 | |||
140 | }; |